import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { SRobIslandGuildInfo } from "../../../../Message/Game/SRobIslandGuildInfo";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Cache } from "../../cache/Cache";
import { GameConst } from "../../../component/gconst/GameConst";
import { Language } from "../../../../extend/language/Language";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { DisplayUtil } from "../../../common/DisplayUtil";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ClockManager } from "../../manager/ClockManager";
import { Global } from "../../../../com/gengine/global/Global";
import { SecTimerView } from "../common/SecTimerView";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { PetIslandPowerInfoItemRenderer } from "./renderer/PetIslandPowerInfoItemRenderer";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GTileList } from "../../../../com/mui/controls/GTileList";
import { GImageBitmap } from "../../../../com/mui/controls/GImageBitmap";
type int = number;
//class PetIslandPowerPanel
    
    export  class PetIslandPowerPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            return;
        }

        /* internal  */onPositionHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            return;
        }

        /* internal  */onTipTxtLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandMapShow));
            return;
        }

        /* internal  */onClickAddTimeBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;
            var powerBaseInfo: SRobIslandGuildInfo;
            var time: int;
            var clickHandler: Function;
            var str: string;

            var loc1;
            time = 0;
            clickHandler = null;
            str = null;
            e = arg1;
            clickHandler = (arg1: int): void
            {
                if (arg1 == Alert.YES) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandAddAttackTime, time));
                }
                return;
            }
            powerBaseInfo = Cache.instance.petIsland.powerBaseInfo;
            time = powerBaseInfo.extraAttackTimes + 1;
            if (powerBaseInfo) 
            {
                if (powerBaseInfo.attackTimes < GameConst.RobIslandAttackTimes) 
                {
                    str = Language.getStringByParam(28252, time * GameConst.RobIslandExtraAttackCost);
                }
                else 
                {
                    str = Language.getStringByParam(28253, time * GameConst.RobIslandExtraAttackCost);
                }
                Alert.show(str, null, Alert.YES | Alert.NO, null, clickHandler);
            }
            return;
        }

        /* internal  */set listData(arg1: Array<any>)
        {
            this._islandNum.text = Language.getStringByParam(28131, arg1.length, 5);
            this._list.dataProvider = new DataProvider(arg1);
            this._list.drawNow();
            if (arg1.length > 0) 
            {
                DisplayUtil.removeMe(this._noOccupySp);
            }
            else 
            {
                this.addChild(this._noOccupySp);
                if (!this._noOccupyTxt) 
                {
                    this._noOccupyTxt = ObjCreate.createGImageBitmap(ImagesConst.PetIslandNoOccupyTxt, 160, 80, this._noOccupySp);
                }
            }
            return;
        }

        public set personalInfoUpata(arg1: SRobIslandGuildInfo)
        {
            var loc2=0;
            this._data = arg1;
            this.listData = arg1.places;
            this._number.htmlText = Language.getStringByParam(28114, HTMLUtil.addColor(arg1.memberCount.toString(), GlobalStyle.color2));
            this._attackTime.htmlText = Language.getStringByParam(28116, HTMLUtil.addColor(arg1.attackTimes + "/" + (GameConst.RobIslandAttackTimes + arg1.extraAttackTimes), GlobalStyle.color2));
            this._inventory.htmlText = Language.getStringByParam(28115, HTMLUtil.addColor(arg1.grass.toString(), GlobalStyle.color2));
            var loc1=ClockManager.instance.nowDate;
            if (Global.isDebugModle) 
            {
                loc2 = arg1.lastAttackDt.time / 1000 + 120 - loc1.time / 1000;
            }
            else 
            {
                loc2 = arg1.lastAttackDt.time / 1000 + GameConst.RobIslandGuildAttackCD - loc1.time / 1000;
            }
            if (arg1.extraAttackTimes >= GameConst.RobIslandExtraAttackTimes) 
            {
                this._addTimeTxt.htmlText = Language.getString(28256);
                this._addTimeBtn.enabled = false;
            }
            else 
            {
                this._addTimeTxt.htmlText = Language.getStringByParam(28255, (arg1.extraAttackTimes + 1) * GameConst.RobIslandExtraAttackCost);
                this._addTimeBtn.enabled = true;
            }
            this._tfLeftTime.setLeftTime(loc2);
            return;
        }

        /* internal  */onResCompl(): void
        {
            ObjCreate.createGBitmap(ImagesConst.PetIslandPowerBasePowerInfoText, 239, 25, this);
            ObjCreate.createGBitmap(ImagesConst.PetIslandPowerBasePowerIslandText, 239, 128, this);
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(-1, 15, 565, 35, this, ImagesConst.RbListHeader);
            ObjCreate.createBg(-1, 120, 565, 35, this, ImagesConst.RbListHeader);
            ObjCreate.createGImageBitmap(ImagesConst.PetIslandNoOccupyBg, 1, 150, this);
            this._addTimeBtn = ObjCreate.createGButton(Language.getString(28254), 407, 59, 62, 24, this);
            this._addTimeTxt = ObjCreate.createGTextField("", 475, 60, 60, 20, this, GlobalStyle._textFormat5);
            this._addTimeTxt.mouseEnabled = false;
            this._number = ObjCreate.createGTextField("", 80, 60, 150, 20, this, GlobalStyle._textFormat9);
            this._number.mouseEnabled = false;
            this._attackTime = ObjCreate.createGTextField("", 315, 60, 150, 20, this, GlobalStyle._textFormat9);
            this._attackTime.mouseEnabled = false;
            this._inventory = ObjCreate.createGTextField("", 80, 90, 220, 20, this, GlobalStyle._textFormat9);
            this._inventory.addEventListener(flash.events.TextEvent.LINK, this.onPositionHandler);
            this._tfLeftTime = new SecTimerView();
            this._tfLeftTime.mouseEnabled = false;
            this._tfLeftTime.setParse(Language.getString(28201));
            this._tfLeftTime.defaultTextFormat = new GTextFormat(FontUtil.songtiName, 12, GlobalStyle.color7Uint);
            this._tfLeftTime.filters = [FilterConst.glowFilter];
            ObjCreate.setObjAttri(this._tfLeftTime, 315, 90, 200, 20, this);
            ObjCreate.createGTextField(Language.getString(28244), 315, 105, 220, 20, this, GlobalStyle._textFormat5);
            this._islandNum = ObjCreate.createGTextField("", 330, 127, 150, 28, this, GlobalStyle._textFormat5);
            this._islandNum.mouseEnabled = false;
            this._lvTxt = ObjCreate.createGTextField("", 37, 149, 150, 28, this, GlobalStyle._textFormat6);
            this._lvTxt.mouseEnabled = false;
            this._list = ObjCreate.createTileList(3, 170, 560, 340, this);
            this._list.scrollPolicy = ScrollPolicy.OFF;
            this._list.columnWidth = 550;
            this._list.rowHeight = 62;
            this._list.setStyle("cellRenderer", PetIslandPowerInfoItemRenderer);
            this._noOccupySp = new Object /* flash.display.Sprite */();
            ObjCreate.setObjAttri(this._noOccupySp, 1, 150, -1, -1);
            ObjCreate.createBitmap(ImagesConst.Fire, 65, 250, this._noOccupySp);
            var loc1=ObjCreate.createGTextField(Language.getString(28227), 90, 255, 500, 20, this._noOccupySp, GlobalStyle._textFormat2, true);
            loc1.addEventListener(flash.events.TextEvent.LINK, this.onTipTxtLinkHandler);
            this._addTimeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onClickAddTimeBtnHandler);
            LoaderHelp.addResCallBack(ResFileConst.PetIslandPowerBase, this.onResCompl);
            return;
        }

        /* internal */ /* var */_number: GTextFiled;

        /* internal */ /* var */_attackTime: GTextFiled;

        /* internal */ /* var */_addTimeBtn: GButton;

        /* internal */ /* var */_addTimeTxt: GTextFiled;

        /* internal */ /* var */_inventory: GTextFiled;

        /* internal */ /* var */_tfLeftTime: SecTimerView;

        /* internal */ /* var */_islandNum: GTextFiled;

        /* internal */ /* var */_list: GTileList;

        /* internal */ /* var */_lvTxt: GTextFiled;

        /* internal */ /* var */_noOccupyTxt: GImageBitmap;

        /* internal */ /* var */_noOccupySp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_data: SRobIslandGuildInfo;
    }
